*------------------------------PLEASE READ-------------------------------------*

/*

REPLICATION FILE FOR TABLE 2 AND FIGURE 3 and TABLE C1-C12
AUTHOR: ZHENHUAN LEI & YISHUANG LI
DATE: 11/13/2023
SOFTWARE: STATA 17 SE OPERATED ON WINDOWS 11

STATA PACKAGE NEEDED: 
	ssc install estout, replace 
	ssc install coefplot, replace
	ssc install gtools, replace
	ssc install reghdfe, replace
	ssc install ftools
	ssc install interflex
*/

*-------------------------- Set up the environment ---------------------------*
	clear
	use ../data/case_data.dta
	
*** Define control variables ***	
	
	global cont_base i.dispute c.stake_bi i.court_level  i.local_plaintiff i.plaintiff i.other_pro 

	global cont_firm i.plaintiff##c.total_return_rate i.plaintiff##c.debt_rate i.plaintiff##c.lemploy ///
	i.plaintiff##c.firm_age i.plaintiff##c.net_profit i.plaintiff##c.net_cash_flow i.plaintiff##c.reg_cap_bi ///
	i.plaintiff##i.firm_pc i.firm1_local##c.total_return_rate i.firm1_local##c.debt_rate ///
	i.firm1_local##c.lemploy i.firm1_local##c.firm_age i.firm1_local##c.net_profit ///
	i.firm1_local##c.net_cash_flow i.firm1_local##c.reg_cap_bi i.firm1_local##i.firm_pc		
	
	global firm_att i.plaintiff##c.total_return_rate i.plaintiff##c.debt_rate i.plaintiff##c.lemploy ///
	i.plaintiff##c.firm_age i.plaintiff##c.net_profit i.plaintiff##c.net_cash_flow ///
	i.plaintiff##c.reg_cap_bi i.plaintiff##i.firm_pc		  
	
	global firm_att1  total_return_rate debt_rate lemploy firm_age net_profit net_cash_flow reg_cap_bi firm_pc
	global firm_att2 total_return_rate debt_rate lemploy firm_age net_profit net_cash_flow reg_cap_bi pr_tax pr_govsub firm_pc 

	global cont_city population_hr_c gdp_percapita_c publicfinance_income_c gdp_growth_c city_total_ipo ///
	tax_vadded_c investment_fixed_c population_unemployed_c gdp_secondary_c gdp_tertiary_c publicfinance_expenditure_c

*** Generating variables ***  
	* pre- post treatment variables for dynamic DID
	gen post0 = (trial_year == reform_50_year) if (!mi(trial_year) & !mi(reform_50_year))
	gen post1 = (trial_year == reform_50_year + 1) if (!mi(trial_year) & !mi(reform_50_year))
	gen post2 = (trial_year >= reform_50_year + 2) if (!mi(trial_year) & !mi(reform_50_year)) 

	gen pre1 = (trial_year == reform_50_year - 1) if (!mi(trial_year) & !mi(reform_50_year))
	gen pre2 = (trial_year == reform_50_year - 2) if (!mi(trial_year) & !mi(reform_50_year))
	gen pre3 = (trial_year == reform_50_year - 3) if (!mi(trial_year) & !mi(reform_50_year))
	gen pre4 = (trial_year <= reform_50_year - 4) if (!mi(trial_year) & !mi(reform_50_year))
	replace pre4 = 0 if reform_50_year == 9999
	
	*Measures for Table C4 
	gen reform21 = (centralize_city100 == 1 & centralize_city90 == 0)
	gen reform22 = (centralize_city90 == 1 & centralize_city70 == 0)
	gen reform23 = (centralize_city70 == 1 & centralize_city50 == 0)
	gen reform24 = (centralize_city50 == 1 & centralize_city30 == 0)
	gen reform25 = (centralize_city30 == 1 & centralize_city10 == 0)
	gen reform26 = (centralize_city10 == 1 & centralize_city0 == 0)
	gen reform27 = (centralize_city0 == 1)
	
*** Limit the data sample ***

	gen data_sample =  (court_level == 2 | court_level == 1) & arbitration == 0 & reconcile == 0 
	
	* Drop intermediate courts in municipalities
	replace data_sample = 0 if court_level == 2 & municipal == 1 		
	
	* Limit the analysis to the obs with no missing values on control variables
	replace data_sample = 0 if plaintiff == . | dispute == . | stake_bi == . | court_level == . ///
	| other_pro == . | total_return_rate == . | debt_rate == . | lemploy == . | firm_age == . ///
	| net_profit == . | net_cash_flow == . | reg_cap_bi == . | gdp_percapita_c == . ///
	| population_hr_c == . | publicfinance_income_c == . | gdp_growth_c == . | city_total_ipo == . ///
	| tax_vadded_c == . | investment_fixed_c == . | population_unemployed_c == . | gdp_secondary_c == . ///
	| gdp_tertiary_c == . | publicfinance_expenditure_c == .
	
	gen datasample2 = (court_level == 2 | court_level == 1) & (arbitration == 0)    
	replace datasample2 = 0 if  plaintiff == . | dispute == . | stake_bi == . | court_level == . ///
	| other_pro == . | total_return_rate == . | debt_rate == . | lemploy == . | firm_age == . ///
	| net_profit == . | net_cash_flow == . | reg_cap_bi == . | gdp_percapita_c == . ///
	| population_hr_c == . | publicfinance_income_c == . | gdp_growth_c == . | city_total_ipo == . ///
	| tax_vadded_c == . | investment_fixed_c == . | population_unemployed_c == . | gdp_secondary_c == . ///
	| gdp_tertiary_c == . | publicfinance_expenditure_c == .

	
*-------------------------- Regression analysis -------------------------------*
preserve 

	drop if data_sample == 0
	
***Table 2***

	eststo clear
	eststo: qui areg local_win_low centralize_city50 i.pro_code##i.trial_year, a(city_id) vce(cluster city_id)  
	eststo: qui areg local_win_low centralize_city50 $cont_base i.pro_code##i.trial_year, a(city_id) vce(cluster city_id) 		
	eststo: qui areg local_win_low centralize_city50 $cont_base $cont_firm i.pro_code##i.trial_year, a(city_id) vce(cluster city_id)  
	eststo: qui areg local_win_low centralize_city50 $cont_base $cont_firm $cont_city i.pro_code##i.trial_year, a(city_id) vce(cluster city_id) 
	esttab, se b(3) t(3) scalars(N_clust) star(* 0.1 ** 0.05 *** 0.01) keep(centralize_city50) replace


***Figure 3***

	qui areg local_win_low pre4 pre3 pre2 post0 post1 post2 $cont_base $cont_firm $cont_city i.pro_code##i.trial_year, a(city_id) vce(cluster city_id) 

	coefplot, keep(pre4 pre3 pre2 post0 post1 post2) ///
		coeflabels(pre4="<=-4" pre3="-3" pre2="-2" ///
		post0="0" post1="1" post2=">=2") ///
		levels(95) ///
		vertical ///
		yline(0, lp(dash)) ///
		xline(3.5, lp(dash)) ///
		addplot(line @b @at) ///
		ciopts(recast(rcap)) ///
		graphregion(color(gs16)) ///
		ylabel(#7, angle() nogrid) ///
		xtitle(Year Relative to the Start of Judicial Reform) ///
		ytitle(Effect of Reform on Local Firm's Winning Rate)  ///
		scheme(s2mono)
*graph export ../result/Figure3.png, replace
restore

***Table B4***
preserve

	drop if datasample2 == 0

	eststo clear
	eststo: qui areg reconcile centralize_city50 i.pro_code##i.trial_year , a(city_id) vce(cluster city_id)  
	eststo: qui areg reconcile centralize_city50 $cont_base i.pro_code##i.trial_year , a(city_id) vce(cluster city_id)  
	eststo: qui areg reconcile centralize_city50 $cont_base $cont_firm i.pro_code##i.trial_year, a(city_id) vce(cluster city_id)  
	eststo: qui areg reconcile centralize_city50 $cont_base $cont_city $cont_firm i.pro_code##i.trial_year, a(city_id) vce(cluster city_id)  
	esttab , se b(3) t(3) scalars(N_clust) star(* 0.1 ** 0.05 *** 0.01) keep(centralize_city50) 

restore

preserve
    
	drop if data_sample == 0

***Table C1*** 
	eststo clear
	eststo: qui areg local_win_low centralize_city50 $cont_base $cont_city $cont_firm i.pro_code##i.trial_year, a(city_id) vce(cluster city_id)  
	eststo: qui areg local_win_low centralize_city50 i.plaintiff##c.pr_govsub i.firm1_local##c.pr_govsub $cont_base $cont_city  $cont_firm i.pro_code##i.trial_year, a(city_id) vce(cluster city_id) 
	eststo: qui areg local_win_low centralize_city50 i.plaintiff##c.pr_tax i.firm1_local##c.pr_tax $cont_base $cont_city $cont_firm i.pro_code##i.trial_year, a(city_id) vce(cluster city_id)  
	eststo: qui areg local_win_low centralize_city50 i.plaintiff##c.pr_govsub i.firm1_local##c.pr_govsub i.plaintiff##c.pr_tax i.firm1_local##c.pr_tax $cont_base $cont_city $cont_firm i.pro_code##i.trial_year, a(city_id) vce(cluster city_id)  
	esttab , se b(3) t(3) scalars(N_clust) star(* 0.1 ** 0.05 *** 0.01) keep(centralize_city50) 


***Table C2*** 

	eststo clear
	eststo: qui areg local_win_low pre4 pre3 pre2 post0 post1 post2 i.pro_code##i.trial_year, a(city_id) vce(cluster city_id)  
	eststo: qui areg local_win_low pre4 pre3 pre2 post0 post1 post2 $cont_base i.pro_code##i.trial_year, a(city_id) vce(cluster city_id)  
	eststo: qui areg local_win_low pre4 pre3 pre2 post0 post1 post2 $cont_base $cont_firm i.pro_code##i.trial_year, a(city_id) vce(cluster city_id)  
	eststo: qui areg local_win_low pre4 pre3 pre2 post0 post1 post2 $cont_base $cont_city $cont_firm i.pro_code##i.trial_year, a(city_id) vce(cluster city_id)  
	esttab, se b(3) t(3) scalars(N_clust) star(* 0.1 ** 0.05 *** 0.01) keep(pre4 pre3 pre2 post0 post1 post2) 

***Table C3***

	eststo clear
	eststo: qui areg local_win_low c.reform_cont i.pro_code##i.trial_year, a(city_id) vce(cluster city_id)
	eststo: qui areg local_win_low c.reform_cont $cont_base i.pro_code##i.trial_year, a(city_id) vce(cluster city_id)
	eststo: qui areg local_win_low c.reform_cont $cont_base $cont_firm i.pro_code##i.trial_year, a(city_id) vce(cluster city_id) 
	eststo: qui areg local_win_low c.reform_cont $cont_base $cont_city $cont_firm i.pro_code##i.trial_year, a(city_id) vce(cluster city_id) 
	esttab , se b(3) t(3) star(* 0.1 ** 0.05 *** 0.01) keep(reform_cont) 


***Table C4*** 

	eststo clear
	eststo: qui areg local_win_low reform21 $cont_base $cont_city $cont_firm i.pro_code##i.trial_year , a(city_id) vce(cluster city_id)  
	eststo: qui areg local_win_low reform22 $cont_base $cont_city $cont_firm i.pro_code##i.trial_year , a(city_id) vce(cluster city_id)  
	eststo: qui areg local_win_low reform23 $cont_base $cont_city $cont_firm i.pro_code##i.trial_year , a(city_id) vce(cluster city_id)  
	eststo: qui areg local_win_low reform24 $cont_base $cont_city $cont_firm i.pro_code##i.trial_year , a(city_id) vce(cluster city_id)  
	eststo: qui areg local_win_low reform25 $cont_base $cont_city $cont_firm i.pro_code##i.trial_year , a(city_id) vce(cluster city_id)  
	eststo: qui areg local_win_low reform26 $cont_base $cont_city $cont_firm i.pro_code##i.trial_year , a(city_id) vce(cluster city_id)  
	eststo: qui areg local_win_low reform27 $cont_base $cont_city $cont_firm i.pro_code##i.trial_year , a(city_id) vce(cluster city_id)  
	eststo: qui areg local_win_low reform21-reform27 $cont_base $cont_city $cont_firm i.pro_code##i.trial_year , a(city_id) vce(cluster city_id)  
	esttab , se b(3) t(3) star(* 0.1 ** 0.05 *** 0.01) keep(reform*) 

***Table C5***

	eststo clear
	eststo: qui probit local_win_low centralize_city50 i.trial_year i.city_id , vce(cluster city_id) 
	eststo: qui probit local_win_low centralize_city50 $cont_base i.trial_year i.city_id, vce(cluster city_id) 
	eststo: qui probit local_win_low centralize_city50 $cont_base $cont_firm i.trial_year i.city_id , vce(cluster city_id)  
	eststo: qui probit local_win_low centralize_city50 $cont_base $cont_city $cont_firm i.trial_year i.city_id, vce(cluster city_id)  
	esttab , se b(3) t(3) star(* 0.1 ** 0.05 *** 0.01) keep(centralize_city50) 

***Table C6***
 
	eststo clear
	eststo: qui areg local_win_up centralize_city50 i.pro_code##i.trial_year, a(city_id) vce(cluster city_id) 
	eststo: qui areg local_win_up centralize_city50 $cont_base i.pro_code##i.trial_year, a(city_id) vce(cluster city_id)  
	eststo: qui areg local_win_up centralize_city50 $cont_base $cont_firm i.pro_code##i.trial_year, a(city_id) vce(cluster city_id) 
	eststo: qui areg local_win_up centralize_city50 $cont_base $cont_city $cont_firm i.pro_code##i.trial_year, a(city_id) vce(cluster city_id) 
	esttab , se b(3) t(3) star(* 0.1 ** 0.05 *** 0.01) keep(centralize_city50) 

***Table C7***

	eststo clear
	eststo: qui mlogit local_win_final centralize_city50 i.trial_year i.city_id, baseoutcome(0) vce(cluster city_id)  
	eststo: qui mlogit local_win_final centralize_city50  $cont_base i.trial_year i.city_id, baseoutcome(0) vce(cluster city_id) 
	eststo: qui mlogit local_win_final centralize_city50  $cont_base  $cont_firm i.trial_year i.city_id, baseoutcome(0) vce(cluster city_id)  
	eststo: qui mlogit local_win_final centralize_city50  $cont_base $cont_city  $cont_firm i.trial_year i.city_id, baseoutcome(0) vce(cluster city_id) 
	esttab, se b(3) t(3) star(* 0.1 ** 0.05 *** 0.01) keep(centralize_city50) 

***Table C8***
 
	eststo clear
	eststo: qui reghdfe local_win_low centralize_city50 $cont_base $cont_city $firm_att , a(city_id i.pro_code##i.trial_year) vce(cluster city_id) 
	eststo: qui reghdfe local_win_low centralize_city50 $cont_base $cont_city $firm_att , a(city_id i.pro_code##i.trial_year firm_id) vce(cluster city_id) 
	eststo: qui reghdfe local_win_low centralize_city50 $cont_base $cont_city $firm_att , a(city_id i.pro_code##i.trial_year firm_id##plaintiff) vce(cluster city_id) 
	eststo: qui reghdfe local_win_low centralize_city50 $cont_base $cont_city $cont_firm , a(city_id i.pro_code##i.trial_year firm_id##plaintiff firm_id##firm1_local) vce(cluster city_id) 
	esttab , se b(3) t(3) scalars(N_clust) star(* 0.1 ** 0.05 *** 0.01) keep(centralize_city50) 

***Table C9***

	eststo clear
	eststo: qui areg local_win_low centralize_city50##i.other_pro $cont_base $cont_city $cont_firm i.pro_code##i.trial_year, a(city_id) vce(cluster city_id)  
	eststo: qui areg local_win_low centralize_city50##i.local_plaintiff $cont_base $cont_city $cont_firm i.pro_code##i.trial_year, a(city_id) vce(cluster city_id) 
	eststo: qui areg local_win_low centralize_city50##court_level $cont_base $cont_city $cont_firm i.pro_code##i.trial_year, a(city_id) vce(cluster city_id)  
	eststo: qui areg local_win_low centralize_city50##c.stake_bi $cont_base $cont_city $cont_firm i.pro_code##i.trial_year, a(city_id) vce(cluster city_id) 
	esttab , se b(3) t(3) star(* 0.1 ** 0.05 *** 0.01) keep(1.centralize_city50*)

***Table C10 ***

	eststo clear
	eststo: qui areg local_win_low centralize_city50##i.plaintiff  $cont_base $cont_city  $cont_firm i.pro_code##i.trial_year, a(city_id) vce(cluster city_id)  
	eststo: qui areg local_win_low centralize_city50##i.firm1_local  $cont_base $cont_city  $cont_firm i.pro_code##i.trial_year, a(city_id) vce(cluster city_id)  
	eststo: qui areg local_win_low centralize_city50##c.total_return_rate  $cont_base $cont_city  $cont_firm i.pro_code##i.trial_year, a(city_id) vce(cluster city_id)  
	eststo: qui areg local_win_low centralize_city50##c.debt_rate  $cont_base $cont_city  $cont_firm i.pro_code##i.trial_year, a(city_id) vce(cluster city_id)  
	eststo: qui areg local_win_low centralize_city50##c.pr_govsub  $cont_base $cont_city  $cont_firm i.pro_code##i.trial_year, a(city_id) vce(cluster city_id)  
	eststo: qui areg local_win_low centralize_city50##c.pr_tax  $cont_base $cont_city  $cont_firm i.pro_code##i.trial_year, a(city_id) vce(cluster city_id)  
	eststo: qui areg local_win_low centralize_city50##i.manufacture  $cont_base $cont_city  $cont_firm i.pro_code##i.trial_year, a(city_id) vce(cluster city_id)  
	eststo: qui areg local_win_low centralize_city50##i.real_estate  $cont_base $cont_city  $cont_firm i.pro_code##i.trial_year, a(city_id) vce(cluster city_id)  
	eststo: qui areg local_win_low centralize_city50##i.firm_pc  $cont_base $cont_city  $cont_firm i.pro_code##i.trial_year, a(city_id) vce(cluster city_id)  
	esttab, se b(3) t(3) star(* 0.1 ** 0.05 *** 0.01) keep(1.centralize_city50*) 

***Table C11***

	eststo clear
	eststo: qui areg local_win_low  centralize_city50##i.local_nonlisted centralize_city50##i.nonlocal_listed  centralize_city50##i.local_listed i.pro_code##i.trial_year, a(city_id) vce(cluster city_id)  
		lincom 1.centralize_city50 + 1.centralize_city50#1.local_listed
		lincom 1.centralize_city50 + 1.centralize_city50#1.local_nonlisted
		lincom 1.centralize_city50 + 1.centralize_city50#1.nonlocal_listed
	eststo: qui areg local_win_low centralize_city50##i.local_nonlisted centralize_city50##i.nonlocal_listed  centralize_city50##i.local_listed $cont_base i.pro_code##i.trial_year, a(city_id) vce(cluster city_id)  
		lincom 1.centralize_city50 + 1.centralize_city50#1.local_listed
		lincom 1.centralize_city50 + 1.centralize_city50#1.local_nonlisted
		lincom 1.centralize_city50 + 1.centralize_city50#1.nonlocal_listed
	eststo: qui areg local_win_low centralize_city50##i.local_nonlisted centralize_city50##i.nonlocal_listed  centralize_city50##i.local_listed $cont_base $cont_firm i.pro_code##i.trial_year, a(city_id) vce(cluster city_id) 
		lincom 1.centralize_city50 + 1.centralize_city50#1.local_listed
		lincom 1.centralize_city50 + 1.centralize_city50#1.local_nonlisted
		lincom 1.centralize_city50 + 1.centralize_city50#1.nonlocal_listed
	eststo: qui areg local_win_low centralize_city50##i.local_nonlisted centralize_city50##i.nonlocal_listed  centralize_city50##i.local_listed $cont_base $cont_city $cont_firm i.pro_code##i.trial_year, a(city_id) vce(cluster city_id)  
		lincom 1.centralize_city50 + 1.centralize_city50#1.local_listed
		lincom 1.centralize_city50 + 1.centralize_city50#1.local_nonlisted
		lincom 1.centralize_city50 + 1.centralize_city50#1.nonlocal_listed
	esttab , se b(3) t(3) scalars(N_clust) star(* 0.1 ** 0.05 *** 0.01) keep(1.centralize_city50*) 

***Table C12***

	eststo clear
	eststo: qui areg local_win_low centralize_city50##firm_pc  i.pro_code##i.trial_year, a(city_id) vce(cluster city_id)  
	eststo: qui areg local_win_low centralize_city50##firm_pc $cont_base $cont_city $cont_firm i.pro_code##i.trial_year, a(city_id) vce(cluster city_id)  
	eststo: qui areg local_win_low centralize_city50##pc_county centralize_city50##pc_city centralize_city50##firm_nlpc  i.pro_code##i.trial_year, a(city_id) vce(cluster city_id) 
	eststo: qui areg local_win_low centralize_city50##pc_county centralize_city50##pc_city centralize_city50##firm_nlpc  i.pro_code##i.trial_year $cont_base $cont_city $cont_firm, a(city_id) vce(cluster city_id) 
	esttab , se b(3) t(3) scalars(N_clust) star(* 0.1 ** 0.05 *** 0.01) keep(1.centralize_city50*) 

***Figure C1***

    global cont_base local_plaintiff stake_bi dispute court_level plaintiff firm1_local other_pro
	winsor2 total_return_rate debt_rate pr_govsub pr_tax, replace trim cut(5,95)
	
	interflex local_win_low centralize_city50 total_return_rate $cont_base $firm_att1 $cont_city , fe(city_id pro_year_fe ) cluster (city_id) type(binning) saving(../result/FigureC1_Graph1.jpg) yr(-1.5 0.5)   xlabel("Moderator: ROA(%)") dlabel("Reform") ylabel("Local Firm's Winning")
	interflex local_win_low centralize_city50 debt_rate $cont_base $firm_att1 $cont_city , fe(city_id pro_year_fe ) cluster (city_id) type(binning) saving(../result/FigureC1_Graph2.jpg) xlabel("Moderator: Asset-Liability Ratio(%)") dlabel("Reform") ylabel("Local Firm's Winning")
	interflex local_win_low centralize_city50 pr_govsub $cont_base $cont_city $firm_att2 , fe(city_id pro_year_fe ) cluster (city_id) type(binning) saving(../result/FigureC1_Graph3.jpg) xlabel("Moderator: Government Subsidy(% of revenue)") dlabel("Reform") ylabel("Local Firm's Winning")
	interflex local_win_low centralize_city50 pr_tax $cont_base $cont_city $firm_att2 , fe(city_id pro_year_fe ) cluster (city_id) type(binning) saving(../result/FigureC1_Graph4.jpg)  xlabel("Moderator: Business Tax(% of revenue)") dlabel("Reform") ylabel("Local Firm's Winning") 

restore	
	

